<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.jieSuan.zhiFuDanGuanLi"/>  <spring:message code="message.jieSuan.zhongXing"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
                            
    <section class="content-header">
        <h1><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.button.add"/></h1>
        <ol class="breadcrumb">
             <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.zhiFuDanGuanLi"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.button.add"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                
                    <div class="form-group form-group-xs">
                        <label for="name"><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="paymentName" name="paymentBillName" placeholder="<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/>" maxlength="200" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="name"><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.yanZheng.bianMa"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="paymentBillCode" name="paymentBillCode" placeholder="<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.yanZheng.bianMa"/>" maxlength="100" />
                    </div>
                    
                    
                
                    <div class="form-group form-group-xs">
                         <spring:message code="message.jieSuan.chuangJianRiQi"/><spring:message code="message.yanZheng.maoHao"/> 
                       <input class="form-control" type="text" id="createTimeBegin"  name="createTimeBegin"  placeholder="yyyy-MM-dd"
                       onFocus="var endDate=$dp.$('crateTimeEnd');WdatePicker({maxDate:'#F{$dp.$D(\'crateTimeEnd\')}'})" />
                        -
                       <input class="form-control" type="text" id="crateTimeEnd"  name="crateTimeEnd"  placeholder="yyyy-MM-dd"
                       onFocus="WdatePicker({minDate:'#F{$dp.$D(\'createTimeBegin\')}'})"  />
                   </div>
                   <button id="selectWSJ" type="button" class="btn btn-success btn-sm" onclick="gridSerch();"><spring:message code="message.button.seachSpacing"/></button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">

            <label id="addNew"  class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></label>
            <button type="button" onclick="del();" class="btn btn-default btn-sm"><spring:message code="message.jieSuan.shanChuSpacing"/></button>
            <button type="button" onclick="submit(0)" class="btn btn-default btn-sm"><spring:message code="message.button.submitSpacing"/></button>

        </div>
        
        <!-- 支付单新增 -->
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.button.add"/></h5>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group form-group-xs">
                            <label for="recipient-name" class=" control-label" ><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/><spring:message code="message.yanZheng.maoHao"/></label>
                            <div class="">
                                <input type="hidden" name="paymentBillId" id="paymentBillId" value="">
                                <input type="text" class="form-control"id="paymentBillName"  placeholder="<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/>">
                            </div>
                        </div>
                        <div class="form-group form-group-xs">
                            <label for="recipient-name" class=" control-label"><spring:message code="message.lable.remark"/><spring:message code="message.yanZheng.maoHao"/></label>
                            <div class="">
                                <input type="text" class="form-control" id="remark" name="remark" placeholder="<spring:message code="message.lable.remark"/>">
                            </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" onclick="save();" class="btn btn-primary btn-sm"><spring:message code="message.button.saveSpacing"/></button>
                    <button type="button" id="closebtn" class="btn btn-danger btn-sm" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
                </div>
            </div>
        </div>
    </div>
    
  
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
    //加载页面光标在名字框内，位于第一个
    $("#paymentName").focus();
    
  //绑定回车    id="selectWSJ"  
    $('#paymentName,#paymentBillCode,#createTimeBegin,#crateTimeEnd').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectWSJ').click();
        }
    }); 
    
        $(function () {
            
            
            jQuery("#gridlist").jqGrid({
                url: "${ctx}/payment/getPaymentList.html",
                mtype: "POST",
                datatype: "json",
                postData:{"status":0},
                autowidth: true,
                shrinkToFit: false,
                height: 285,
                colNames:[
							'<spring:message code="message.jqGrid.cz"/>',
							'<spring:message code="message.jieSuan.zhiFuDan"/>id',
							'<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.yanZheng.bianMa"/>',
							'<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/>',
							'<spring:message code="message.jieSuan.zongTiaoMuShu"/>',
							'<spring:message code="message.jieSuan.zongJinE"/>',
							'<spring:message code="message.jieSuan.chuangJianShiJian"/>',
							'<spring:message code="message.jieSuan.chuangJianRen"/>',
							'<spring:message code="message.lable.remark"/>',
							'<spring:message code="message.jieSuan.tiJiaoRen"/>',
							'<spring:message code="message.jieSuan.tiJiaoShiJian"/>',
							'<spring:message code="message.lable.status"/>',
							'<spring:message code="message.jieSuan.auditTime"/>',
							'<spring:message code="message.jieSuan.auditPeople"/>',
							'<spring:message code="message.listForm.shenHeBeiZhu"/>',
							'<spring:message code="message.jieSuan.fuShenShiJian"/>',
							'<spring:message code="message.jieSuan.fuShenShiRen"/>',
							'<spring:message code="message.jieSuan.fuShen"/><spring:message code="message.lable.remark"/>',
							'<spring:message code="message.jieSuan.zhiFuTime"/>',
							'<spring:message code="message.jieSuan.zhiFuPeople"/>',
							'<spring:message code="message.listForm.xiuGaiShiJian"/>',
							'<spring:message code="message.listForm.xiuGaiRen"/>'
                          
                          ],
                colModel:[
                    { name: 'oper', width:100, align:"center", sortable:false,
                           formatter : function(val, opts, rowdata) {
                            var str = "";
                           str += "<a href=\"javascript:edit('"+ rowdata.paymentBillId+ "');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.button.edit"/>'></a>"
                             + "<a href='${ctx}/payment/toPaymentAddDetailList.html?paymentBillId="+rowdata.paymentBillId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px 0px' class='opIcon' title='<spring:message code="message.button.addDetail"/>'></a>"
                             + "<a href='${ctx}/payment/toPaymentDetailList.html?paymentBillId="+rowdata.paymentBillId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a>";
                            return str;
                      }  
                    },
                    { name: 'paymentBillId',width:160,align:"center",hidden:true,sortable:false},
                    { name: 'paymentBillCode', width:210, align:"center",sortable:false},
                    { name: 'paymentBillName', width:210, align:"left",sortable:false},
                    { name: 'totalOrders', width:60,align:"center",sortable:false},
                    { name: 'totalAmount', width:80,align:"right",sortable:false,
                    	formatter:function(cellvalue, options, row){
                            return formatAmount(cellvalue, options, row);
                        }	
                    },
                    { name: 'createDateTime', width:140, align:"center",sortable:false},
                    { name: 'createUserName', width:180, align:"left", sortable:false},
                    { name: 'remark', width:160, align:"center", sortable:false},
                    { name: 'submitUserName',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'submitDatetime',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'statusName',hidden:true, width:80, align:"center", sortable:false},
                    { name: 'auditDatetime',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'auditUserName',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'auditRemark',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'reauditDatetime',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'reauditUserName',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'reauditRemark',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'billSettleDatetime',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'billSettleUser',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'updDatetime',width:160,hidden:true,align:"center" ,sortable:false},
                    { name: 'updUser',width:160,hidden:true,align:"center" ,sortable:false}
                    
                ],
                 rowNum: 20,
                 rowList: [10, 20, 50, 100],
                 rownumbers: true,
                 pager: "#gridpage",
                 viewrecords: true,
                 multiselect: true, 
                 
                 caption: "<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.lieBiao"/>",
                 //序号宽度自动变化
                 gridComplete:function(){
                     //序号列宽度自适应（参数为jqgridID）
                     autoRNWidth("gridlist");
                     //数据只有一条时默认选中（参数为jqgridID）
                     selectByOneData("gridlist");
                 },
                 jsonReader: {
                     repeatitems: false,
                     id: "paymentBillId"
                 }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
        
        
      //查询
        function gridSerch() {
        	var paymentBillCode = $.trim($("#paymentBillCode").val());
        	var paymentName = $.trim($("#paymentName").val());
            var createTimeBegin = $.trim($("#createTimeBegin").val());
            var crateTimeEnd = $.trim($("#crateTimeEnd").val());
            
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:{
                        "paymentBillCode":paymentBillCode,
                        "paymentBillName":paymentName,
                        "createTimeBegin":createTimeBegin,
                        "crateTimeEnd":crateTimeEnd
                        },
                        page:1
            }).trigger("reloadGrid"); //重新载入  
        }
      
      //新增
        $('#addNew').click(
                function() {
                    $('.modal-title').html('<spring:message code="message.button.add"/><spring:message code="message.jieSuan.zhiFuDan"/>');
                    $("#paymentBillId").val("");
                    $('#paymentBillName').val("");
                    $('#remark').val("");
                    $('#exampleModal').modal({
                        keyboard : true
                    });
                });
      
        //编辑
        function edit(paymentBillId) {
          $('.modal-title').html('<spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.button.edit"/>');
          $("#paymentBillId").val(paymentBillId);
          var rowdata = $("#gridlist").jqGrid('getRowData', paymentBillId);
          $("#paymentBillName").val(rowdata.paymentBillName);
          $("#remark").val(rowdata.remark);
          $('#exampleModal').modal({
              keyboard : true
          });
      }  
   
       
       
      //保存
        function save() {
        	var paymentBillId = $.trim($('#paymentBillId').val());
            var paymentBillName = $.trim($('#paymentBillName').val());
            if (paymentBillName.length < 1){
                $.HN.message.alert('<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.jieSuan.zhiFuDan"/><spring:message code="message.listForm.mingCheng"/>！','<spring:message code="message.HN.alert.tiShiXinXi"/>','');
                return;
            }
            var remark = $.trim($('#remark').val());
            if (remark.length < 1) {
                $.HN.message.alert('<spring:message code="message.yanZheng.qingShuRu"/><spring:message code="message.lable.remark"/>！','<spring:message code="message.HN.alert.tiShiXinXi"/>','');
                return;
            }
            $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(
                function(e) {
                    if (e) {
                        $.ajax({
                            url : "${ctx}/payment/savePayment.html",//action地址
                            data : {
                            	paymentBillId:paymentBillId,
                            	paymentBillName : paymentBillName,
                                remark : remark,
                            },//传值
                            type : "post",
                            success : function(result) {
                                var result = eval("("+ result+ ")");
                                if ("success" == result) {
                                    $.HN.message.alert('<spring:message code="message.HN.alert.baoCunCheng"/>','<spring:message code="message.listForm.xinXi"/>','success');
                                    gridSerch()
                                    $("#closebtn").click();
                                }  else {
                                    $.HN.message.alert('<spring:message code="message.HN.alert.baoCunBai"/>','<spring:message code="message.listForm.xinXi"/>','success');
                                    gridSerch()
                                    $("#closebtn").click();
                                }
                            } 
                        });
                        
                        
                    }
                });
            }
        
      
     
      
    //删除
      function del(){
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("<spring:message code="message.jieSuan.pleaseSelectShanChuZhiFuDan"/>", "<spring:message code="message.HN.alert.type"/>", "error");
                return;
            }
            
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                list.push({"paymentBillId":rowdata.paymentBillId});
            }
            $.HN.message.confirm('<spring:message code="message.jieSuan.queDingShanChuMa"/>', '', '').on(function (e) {
                if (e) {
	                $.post("${ctx}/payment/deletePayment.html", {
	                	"array" : json.jsonToString(list)
	                }, function(result) {
	                    if (result.success) {
	                        $.HN.message.alert("删除成功！", "<spring:message code="message.HN.alert.type"/>", "success");
	                        gridSerch();
	                    } else {
	                        $.HN.message.alert("删除失败！", "<spring:message code="message.HN.alert.type"/>", "error");
	                    }
	                }, "json");
                }
            });
        }
    
      //提交
      function submit(code){
         
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要提交的支付单！", "<spring:message code="message.HN.alert.type"/>", "error");
                return;
            }
            $.HN.message.confirm('<spring:message code="message.jieSuan.queDingTiJiaoMa"/>', '', '').on(function (e) {
                if (e) {
                    var list = [];
                    for (var i=0; i<rowIds.length; i++) {
                        rowId = rowIds[i];
                        var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                        if (rowdata.totalOrders=="" || rowdata.totalOrders<=0){
                        	$.HN.message.alert("<spring:message code="message.jieSuan.meiYouMingXingBuKeTiJiao"/>", "<spring:message code="message.HN.alert.type"/>", "error");
                			return;
                        }
                        
                        list.push({"paymentBillId":rowdata.paymentBillId}); 
                    }
                    $.post("${ctx}/payment/submitPayment.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                            gridSerch();
                            $.HN.message.alert("提交成功！", "<spring:message code="message.HN.alert.type"/>", "success");
                        } else {
                            if(result.code ==1){
                                batchJoin(1);
                            }
                            $.HN.message.alert(result.msg, "<spring:message code="message.HN.alert.type"/>", "error");
                        }
                    }, "json");
                }
            });
        }
      
      
      
      
      
         
    </script>
</body>
</html>












